﻿using System.Linq;
using System.Xml;
using DataScripter.Scripting;
using DataScripter.Scripting.Processes;

namespace DataScripter.XmlInterpreter.XmlInterpreters
{
	internal class TableListInterpreter : IXmlInterpreter<ITableList>
	{
		private readonly IEngine _engine;
		private const string TABLE = "Table";

		public TableListInterpreter(IEngine engine)
		{
			_engine = engine;
		}

		public ITableList InterpretElement(XmlElement element)
		{
			string name = element.GetAttribute("Name");
			ITableList tableList = new TableList(name);
			foreach (string tableName in
				from child in element.ChildNodes.OfType<XmlElement>() 
				where child.Name == TABLE 
				select child.GetAttribute("Name"))
			{
				tableList.AddTable(tableName);
			}

			return tableList;
		}
	}
}